package myJs

import myJs.admin.{Admin, AdminCp}
import myJs.admin.companyMemeberManage.CompanyMemberManage
import myJs.admin.memberManage.MemberManage
import myJs.admin.specialMemberManage.SpecialMemberManage
import myJs.admin.wechatMemberManage.WechatMemberManage
import myJs.companyMember.{CompanyMember, CompanyMemberCp}
import myJs.cps.NotFoundCp
import myJs.member.{Member, MemberCp}
import myJs.myPkg.{CSSTransition, TransitionGroup, _}
import myJs.specialMember.{SpecialMember, SpecialMemberCp}
import myJs.test.TestCp
import myJs.wechatMember.{WechatMember, WechatMemberCp}
import slinky.core._
import slinky.core.annotations.react
import slinky.web.html._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("resources/logo.svg", JSImport.Default)
@js.native
object ReactLogo extends js.Object

@react object App {
  type Props = Unit

  val component = FunctionalComponent[Props] { props =>

    val location = ReactRouterDOM.useLocation()

    div(className := "App")(

      Routes(
        Route(path = "", element = LoginCp()),
        Route(path = "test", element = TestCp()),
        Route(path = Admin.prefix, element = AdminCp())(
          Admin.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
        Route(path = Member.prefix, element = MemberCp())(
          Member.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
        Route(path = SpecialMember.prefix, element = SpecialMemberCp())(
          SpecialMember.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
        Route(path = CompanyMember.prefix, element = CompanyMemberCp())(
          CompanyMember.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
        Route(path = WechatMember.prefix, element = WechatMemberCp())(
          WechatMember.pages.map { x =>
            val finalCp = TransitionGroup(
              CSSTransition(key = x.path, classNames = "fade", timeout = 300, location = location)(
                x.cpE
              )
            )
            Route(key = x.path, path = x.path, element = finalCp)
          },
          Route(path = "*", element = NotFoundCp())
        ),
      ),

    )

  }


}
